<?php 
class cls_control_favorite extends cls_control_base
{
	function get_all_favorite()
	{
		$favorite_serve = cls_serve_base::get_instance($this->name);
		if(!isset($_COOKIE['b2c_customerid']))
		{
			$notlogin = return_info(false, "登陆超时");
			echo json_encode($notlogin);
			return;
		}
		$customerid = $_COOKIE['b2c_customerid'];
	
		$result = $favorite_serve->get_all_favorite($customerid);
	
		echo json_encode($result);
	}
	
	function add_favorite()
	{
		$favorite_serve = cls_serve_base::get_instance($this->name);
		if(!isset($_COOKIE['b2c_customerid']))
		{
			$notlogin = return_info(false, "登陆超时");
			echo json_encode($notlogin);
			return;
		}
		$customerid = $_COOKIE['b2c_customerid'];
		$productid = $_REQUEST['productid'];
	
		$productid = mysql_real_escape_string($productid);
		
		if(cls_control_base::check_if_empty($productid))
		{
			$message = return_info(false, "没有指定产品ID");
			echo json_encode($message);
			return;
		}
		
		$result = $favorite_serve->add_favorite($customerid, $productid);
	
		echo json_encode($result);
	}
	
	function delete_favorite()
	{
		$favorite_serve = cls_serve_base::get_instance($this->name);
		if(!isset($_COOKIE['b2c_customerid']))
		{
			$notlogin = return_info(false, "登陆超时");
			echo json_encode($notlogin);
			return;
		}
		$customerid = $_COOKIE['b2c_customerid'];
		$favoriteid = $_REQUEST['favoriteid'];
	
		$favoriteid = mysql_real_escape_string($favoriteid);
		
		if(cls_control_base::check_if_empty($favoriteid))
		{
			$message = return_info(false, "没有指定收藏ID");
			echo json_encode($message);
			return;
		}
		
		$result = $favorite_serve->delete_favorite($customerid, $favoriteid);
	
		echo json_encode($result);
	}
	
	function check_favorite_exist()
	{
		$favorite_serve = cls_serve_base::get_instance($this->name);
		if(!isset($_COOKIE['b2c_customerid']))
		{
			$notlogin = return_info(false, "登陆超时");
			echo json_encode($notlogin);
			return;
		}
		$customerid = $_COOKIE['b2c_customerid'];
		$productid = $_REQUEST['productid'];
	
		$productid = mysql_real_escape_string($productid);
		
		if(cls_control_base::check_if_empty($productid))
		{
			$message = return_info(false, "没有指定产品ID");
			echo json_encode($message);
			return;
		}
		
		$result = $favorite_serve->check_favorite_exist($customerid, $productid);
	
		echo json_encode($result);
	}
}
?>